/*
 * @Author: 追逐的娃 kangchao_php@163.com
 * @Date: 2024-06-25 14:10:58
 * @LastEditors: 追逐的娃 kangchao_php@163.com
 * @LastEditTime: 2025-01-08 15:35:51
 * @FilePath: \vue-project\vite.config.js
 * @Description:
 *
 */
import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { ElementPlusResolver, ArcoResolver } from 'unplugin-vue-components/resolvers'
import WindiCSS from 'vite-plugin-windicss'
//压缩文件插件 此处使用Brotli 压缩插件。还用gzip压缩方法常用
import viteCompression from 'vite-plugin-compression'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    // 引入Brotli 压缩算法，并对大于 10KB 的文件进行压缩，并以 .br 作为扩展名来表示压缩过的文件。
    viteCompression({
      algorithm: 'brotliCompress', // 使用 Brotli 压缩算法
      threshold: 10240, // 设置文件大小的阈值，单位为字节
      ext: '.br' // 输出的压缩文件扩展名
    }),
    WindiCSS(),
    vue({
      reactivityTransform: true
    }),
    AutoImport({
      resolvers: [ElementPlusResolver(), ArcoResolver()]
    }),
    Components({
      resolvers: [
        ElementPlusResolver(),
        ArcoResolver({
          sideEffect: true
        })
      ]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },

  //配置跨域问题
  server: {
    proxy: {
      '/api': {
        // target: 'http://www.main.com/admin',
        target: 'http://api.yunjihuahai.xyz/admin/v1',
        changeOrigin: true, //将主机头的起点更改为目标URL
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})
